package com.example.atry;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.ImageView;

public class zhen extends AppCompatActivity {   //用于帧布局

    private int[] imageResources = {R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4, R.drawable.image5};
    private int currentImageIndex = 0;
    private FrameLayout frameLayout;
    private Handler handler = new Handler();
    private Runnable runnable = new Runnable() {
        @Override
        public void run() {
            rotateImages();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhen);

        frameLayout = findViewById(R.id.frame_layout);

        // 初始化ImageViews
        for (int imageResource : imageResources) {
            ImageView imageView = new ImageView(this);
            imageView.setImageResource(imageResource);
            frameLayout.addView(imageView);
        }

        // 开始轮播
        handler.postDelayed(runnable, 3000); // 每3秒更换一张图片
    }

    private void rotateImages() {
        currentImageIndex = (currentImageIndex + 1) % imageResources.length;
        for (int i = 0; i < frameLayout.getChildCount(); i++) {
            ImageView imageView = (ImageView) frameLayout.getChildAt(i);
            if (i == currentImageIndex) {
                imageView.setVisibility(View.VISIBLE);
            } else {
                imageView.setVisibility(View.GONE);
            }
        }
        handler.postDelayed(runnable, 3000);
    }


}

